/*
 * Copyright (c) 2024 endless-sky
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include <string>
#include <chrono>
#include <mutex>
#include "nlohmann/json.hpp"
#include "utils_callback_list.h"

namespace El {
namespace Record {

class IndexWriter {
public:
    static IndexWriter &GetInstance();

    /**
     * @brief Add or update video entry in the index file
     * @param storePath Absolute storage path (must start with '/')
     * @param videoIndex Video index information
     * @return true if successful, false otherwise
     * @note The storePath must be an absolute path starting with '/'
     */
    bool WriteVideoIndex(const std::string &absolutePath, const nlohmann::json &videoIndex);

    /**
     * @brief Add or update image entry in the index file
     * @param storePath Absolute storage path (must start with '/')
     * @param imageIndex Image index information in JSON format
     * @return true if successful, false otherwise
     * @note The storePath must be an absolute path starting with '/'
     */
    bool WriteImageIndex(const std::string &absolutePath, const nlohmann::json &imageIndex);

private:
    IndexWriter() = default;
    ~IndexWriter() = default;

    /**
     * @brief 创建新的索引文件
     * @return 新创建的索引JSON对象
     */
    nlohmann::json CreateNewIndex();
};

} // namespace Record
} // namespace El